﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;
using System.Configuration;

namespace WXYW
{
    public partial class GetProductDirectly : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialPage();
            }
        }

        private void InitialPage()
        {
            ApplicationService applicatonservice = new ApplicationService();
            ApplicationForm applicaton = applicatonservice.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if(!applicaton.UserReference.IsLoaded)
            {
                applicaton.UserReference.Load();
            }
           
            emailLabel.Text =applicaton.User.UserEmail;
            toLabel.Text = applicaton.User.UserName;
            bodyTextBox.Text = ConfigurationManager.AppSettings["SendProductEmailA"].ToString().Replace("{name}", applicaton.User.UserName).Replace("{rmacode}", applicaton.ApplicationCode);
        }

        protected void sendLinkButton_Click(object sender, EventArgs e)
        {
            ApplicationService applicatonservice = new ApplicationService();
            ApplicationForm applicationForm = applicatonservice.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            applicationForm.NortificationDatetime = DateTime.Now;
            applicationForm.SendWay = "A";
            applicatonservice.UpdateApplication(applicationForm);

            EmailService.SendEmail(emailLabel.Text, "发货通知", bodyTextBox.Text);
            ClientScript.RegisterStartupScript(this.GetType(), "tip", "alert('发送成功!');", true);
        }
    }
}
